import { createRouter, createWebHashHistory } from "vue-router";
import Home from "../views/Home.vue";
import {ElMessage} from "element-plus";

const routes = [{
        path: '',
        redirect: '/init'
    }, {
        path: "",
        name: "Home",
        component: Home,
        children: [
            {
                path: "/index",
                name: "index",
                meta: {
                    title: '首页'
                },
                component: () =>
                    import ("../views/Dashboard.vue")
            },
            {
                path: "/screen",
                name: "screen",
                meta: {
                    title: '病人一览表'
                },
                component: () =>
                    import ("../views/Screen.vue")
            },
            {
                path: "/lobby",
                name: "lobby",
                meta: {
                    title: '走廊提示'
                },
                component: () =>
                    import ("../views/Lobby.vue")
            },
            // {
            //     path: "/duty",
            //     name: "duty",
            //     meta: {
            //         title: '值班信息'
            //     },
            //     component: () =>
            //         import ("../views/Duty.vue")
            // },
            {
                path: "/bed",
                name: "bed",
                meta: {
                    title: '床位一览'
                },
                component: () =>
                    import ("../views/BedList.vue")
            },
            {
                path: "/patient",
                name: "patient",
                meta: {
                    title: '呼叫病人'
                },
                component: () =>
                    import ("../views/CallPatient.vue")
            },
            {
                path: "/callRecord",
                name: "callRecord",
                meta: {
                    title: '通话记录'
                },
                component: () =>
                    import ("../views/CallRecord.vue")
            },
            {
                path: "/broadcast",
                name: "broadcast",
                meta: {
                    title: '定时广播',
                },
                component: () =>
                    import ("../views/BroadcastList.vue")
            },
            {
                path: "/audio",
                name: "audio",
                meta: {
                    title: '语音库',
                },
                component: () =>
                    import ("../views/VoiceList.vue")
            },
            {
                path: "/shout",
                name: "shout",
                meta: {
                    title: '广播喊话'
                },
                component: () =>
                    import ("../views/Shout.vue")
            },
            {
                path: "/setting",
                name: "setting",
                meta: {
                    title: '设置'
                },
                component: () =>
                    import ("../views/Setting.vue")
            },
            {
                path: '/user',
                name: 'user',
                meta: {
                    title: '个人中心'
                },
                component: () =>
                    import ('../views/User.vue')
            }
        ]
    },
    {
        path: "/login",
        name: "Login",
        meta: {
            title: '登录'
        },
        component: () =>
            import ( /* webpackChunkName: "login" */ "../views/Login.vue")
    },
    {
        path: "/init",
        name: "init",
        meta: {
            title: '初始化'
        },
        component: () =>
            import ("../views/Init.vue")
    },
    {
        path: "/screenBig",
        name: "screenBig",
        meta: {
            title: '大屏一览'
        },
        component: () =>
            import ( /* webpackChunkName: "login" */ "../components/ScreenBig.vue")
    },
    {
        path: '/refresh',
        name: 'refresh',
        component: () => import("../components/refresh.vue")
    }
];

const router = createRouter({
    history: createWebHashHistory(),
    routes
});


// router.beforeEach((to, from, next) => {
//     document.title = to.meta.title;
//     const role = localStorage.getItem('ms_username');
//     if (!role && to.path !== '/login') {
//         next('/login');
//     } else if (to.meta.permission) {
//         // 如果是管理员权限则可进入，这里只是简单的模拟管理员权限而已
//         role === 'admin'
//             ? next()
//             : next('/403');
//     } else {
//         next();
//     }
// });

export default router;